<template>
  <div class="container-fluid">
    <table class="table" v-if="isLoaded">
      <thead>
        <tr>
          <td>提交时间</td>
          <td>姓名</td>
          <td>工号</td>
          <td>年龄</td>
          <td>性别</td>
          <td>部门</td>
          <td>岗位</td>
          <td>实际参与管制工作的开始时间</td>
          <td>工作年限</td>
          <td>贝尔宾测试结果</td>
          <td>霍兰德测试结果I</td>
          <td>霍兰德测试结果II</td>
          <td>霍兰德测试结果III</td>
        </tr>
      </thead>
      <tbody>
        <TableLine v-for="record in coreData" :key="record.id" :lineData="record"></TableLine>
      </tbody>
    </table>
  </div>
</template>

<script>
import TableLine from "@/components/admin/elements/TableLine.vue";
export default {
  name: "AdminMainView",
  components: {
    TableLine
  },
  data() {
    return {
      //{idx,time,id,name,surinfo:{...},belbin:{...},holland:{...}}
      coreData: null,
      isLoaded: false
    };
  },
  computed: {
    devMode() {
      return this.$store.state.devMode;
    },
    isValid() {
      return this.$store.state.isAdmin;
    },
    tokenStr() {
      return this.$store.state.tokenStr;
    }
  },
  methods: {
    loadData() {
      this.axios
        .post("backend.php", {
          action: "load",
          payload: {
            token: this.tokenStr
          }
        })
        .then(response => {
          if (this.devMode) {
            window.console.log(response.data.content);
          }
          this.isLoaded = true;
          this.coreData = response.data.content;
        })
        .catch(error => {
          if (this.devMode) {
            window.console.log(error);
          }
        });
    }
  },
  mounted() {
    if (!this.isValid) {
      this.$router.push("verify");
    }
  },
  created() {
    this.loadData();
  }
};
</script>

<style scoped>
</style>